
//https://leetcode.cn/problems/find-the-highest-altitude/submissions/
int largestAltitude(int* gain, int gainSize) {
    int* arr = (int*)malloc(sizeof(int) * (gainSize + 1));
    if (arr == NULL)
    {
        perror("malloc fail");
        exit(-1);
    }

    arr[0] = 0;

    int i = 1;
    while (i <= gainSize)
    {
        arr[i] = arr[i - 1] + gain[i - 1];
        i++;
    }

    int maxgain = arr[0];
    i = 1;
    while (i <= gainSize)
    {
        if (maxgain < arr[i])
        {
            maxgain = arr[i];
        }
        i++;
    }

    free(arr);
    return maxgain;
}